package com.example.userdemo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/api/**")  // 允许所有后端接口
                .allowedOrigins("http://localhost:63342")  // 改为前端实际域名
                .allowedMethods("GET", "POST")  // 支持的请求方式
                .allowCredentials(true)
                .maxAge(3600);
    }
}